package com.springboot.common.convert;

import com.springboot.common.resolver.MyHandlerMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

/**
 * @Author: TongRui乀
 * @Date: 2020-04-12 15:10
 * @description：  继承之后SpringMVC 默认的静态文件配置已经失效 需要重新配置
 */
@Configuration
public class MvcConvertConfig extends WebMvcConfigurationSupport {

    @Autowired
    private String2DateConvert string2DateConvert;

    @Autowired
    private String2ListConvert string2ListConvert;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/img").addResourceLocations("/img/");
        registry.addResourceHandler("/static/css").addResourceLocations("/css/");
        registry.addResourceHandler("/static/js").addResourceLocations("/js/");
        registry.addResourceHandler("/static/swf").addResourceLocations("/swf/");
        registry.addResourceHandler("/static/media").addResourceLocations("/media/");
    }


    @Override
    protected void addFormatters(FormatterRegistry registry) {
        registry.addConverter(string2DateConvert);
        registry.addConverter(string2ListConvert);
    }

    @Autowired
    private MyHandlerMethodArgumentResolver myHandlerMethodArgumentResolver;

    @Override
    protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(myHandlerMethodArgumentResolver);
    }

    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {

        converters.set(0, new PropertiesHttpMessageConverter());

    }
}
